﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Diagnostics;

namespace MiniBrowser
{
    public class MayhemConnector
    {
        
        #region Singleton
        static readonly MayhemConnector instance = new MayhemConnector();

        // Explicit static constructor to tell C# compiler
        // not to mark type as beforefieldinit
        static MayhemConnector()
        {
        }

        MayhemConnector()
        {
            Url = "http://bing.com/";
        }

        public static MayhemConnector Instance
        {
            get { return instance; }
        }
        #endregion

        public string IP { get; set; }

        public string Port { get; set; }

        public string Url { get; set; }

        public void SendRequest()
        {
            //try
            //{
                WebClient wc = new WebClient();

                string url = Url.Replace("/", "%2F");
                
            /*int index = url.IndexOf("://");
                url = url.Remove(0, index + 3);

                if (url.EndsWith("/"))
                {
                    url = url.Substring(0, url.Length - 1);
                }
                */

                try
                {
                    Uri uri = new Uri(String.Format("http://{0}:{1}/Mayhem/Url?guid={2}&url={3}", IP, Port, "guid", url));
                    Debug.WriteLine("Requesting url " + uri);
                    wc.OpenReadAsync(uri);
                }
                catch { }

                
                
                
                
            /*}
            catch(Exception e)
            {
                Debug.WriteLine(e.Message);
            }(*/
        }
    }
}
